package com.hownoon.parquet1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class ParquetReduce extends Reducer<NullWritable, LongWritable,NullWritable,LongWritable> {
    @Override
    protected void reduce(NullWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);
        long sum=0;
        for(LongWritable longWritable:values){
            sum=sum+longWritable.get();
        }
        LongWritable longWritable=new LongWritable(sum);
        context.write(NullWritable.get(),longWritable);
    }
    /*@Override
    protected void reduce(ImmutableBytesWritable key, Iterable<Put> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);
        for(Put put:values){
            context.write(NullWritable.get(),put);
        }

    }*/

    /*@Override
    protected void reduce(NullWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);
        for(Text text:values){
            String a[]=text.toString().split("\t");
            Put put = new Put(Bytes.toBytes(a[0]));
            put.addColumn(Bytes.toBytes("Buy"), Bytes.toBytes("price"), Bytes.toBytes(a[1]));
            put.addColumn(Bytes.toBytes("Buy"), Bytes.toBytes("volume"), Bytes.toBytes(a[2]));
            put.addColumn(Bytes.toBytes("Buy"), Bytes.toBytes("date"), Bytes.toBytes(a[3]));
            context.write(NullWritable.get(),put);
        }

    }*/
    /* @Override
    protected void reduce(LongWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);
        Iterator<Text> iterator = values.iterator();
        while(iterator.hasNext()){
            context.write(key,iterator.next());
        }
    }*/

    /*@Override
    protected void reduce(LongWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        //super.reduce(key, values, context);

        long sum = 0L;
        for(LongWritable longWritable: values){
            sum=sum+longWritable.get();
        }
        LongWritable longWritable=new LongWritable(sum);
        context.write(key,longWritable);

    }*/
}
